package com.wnhz.wnmap.smovie.genre.controller;

import com.wnhz.wnmap.common.result.HttpResp;
import com.wnhz.wnmap.domain.entity.Genre;
import com.wnhz.wnmap.smovie.genre.service.IGenreService;
import com.wnhz.wnmap.smovie.genre.util.PoiUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;
import java.lang.reflect.Method;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;

@Api(tags = "电影类型模块接口")
@RestController
@RequestMapping("api/genre")
@Slf4j
public class GenreController {

    @Autowired
    private IGenreService igs;

    @ApiOperation(value = "findAllGenres", tags = "查询所有电影类型接口")
    @GetMapping("/findAllGenres")
    public HttpResp findAllGenres() {
        return HttpResp.success(igs.findAll());
    }

    @ApiOperation(value = "excelUpload", tags = "上传excel文件接口")
    @PostMapping("/excelUpload")
    @SneakyThrows
    public HttpResp excelUpload(@RequestPart @RequestParam("file") MultipartFile file) {

        log.debug("文件:{}上传成功", file.getOriginalFilename());


        InputStream in = file.getInputStream();
        PoiUtil.getInstance().init(in);

        return HttpResp.success("[excel解析成功]==>" + PoiUtil.getInstance().parseExcel(Genre.class));
    }


    @ApiOperation(value = "findByName", tags = "根据输入的类型名称模糊查询")
    @GetMapping("/findByName")
    public HttpResp findByName(String name){
        return HttpResp.success(igs.findByNameLike(name));
    }
}
